package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.ReservationDto;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/customer/reservation")
public class CustomerReservationController {
    @Autowired
    private ReservationService reservationService;

    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public ResponseResult cancelledCount() {
        return ResponseResult.success(0);
    }

    @GetMapping("/countByTime")
    @ApiOperation("查询每个时间段剩余预约次数")
    public ResponseResult<List<Map<String, String>>> countByTime(Long time) {
        List<Map<String, String>> list = reservationService.countByTime(time);
        return ResponseResult.success(list);
    }

    @PostMapping
    @ApiOperation("新增预约")
    public ResponseResult add(@RequestBody ReservationDto reservationDto) {
        reservationService.add(reservationDto);
        return ResponseResult.success();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询预约列表")
    public ResponseResult<PageResponse<ReservationVo>> page(
            @ApiParam("第页数") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam("每页条数") @RequestParam(defaultValue = "10") Integer pageSize,
            @ApiParam("预约状态") Integer status) {
        PageResponse<ReservationVo> pageResponse = reservationService.getByPage(pageNum, pageSize, status);
        return ResponseResult.success(pageResponse);
    }

    @PutMapping("/{id}/cancel")
    @ApiOperation("取消预约")
    public ResponseResult cancel(@PathVariable Long id) {
        reservationService.cancel(id);
        return ResponseResult.success();
    }
}
